/*
 * Copyright (C) 2000-2007 Wang Pengcheng <wpc0000@gmail.com>
 * Licensed to the Wang Pengcheng under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The LGPL licenses this file to You under the GNU Lesser General Public
 * Licence, Version 2.0  (the "License"); you may not use this file except in
 * compliance with the License.  You may obtain a copy of the License at
 *
 *     http://www.gnu.org/licenses/lgpl.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
//28 Aug 2007
package cn.edu.whu.control;

import java.io.*;

import cn.edu.whu.data.VarList;
/**
 * Edit the template file of the SqlMapConfig.properties
 * In the version of 0.0.1 ,this class is only to copy the template file but not
 * change it.
 * 
 * @author wpc
 * @version 0.0.1
 * 
 */
public class EditConfigPer {

	//Template file's location
	//TODO find the information about the url in the debug and run.
	private static String fileUrl=BasicDataForEdit.TEMPLATE_FILE_DIR+"databaseAction/SqlMapConfig.properties";
	
	private String s="";
	
	private VarList var;
	private String SALE_FILE_NAME="test.properties";
	
	public EditConfigPer(VarList var){
		this.var=var;
	}
	
	public void read()throws Exception{
		FileInputStream storageFile = new FileInputStream(
				fileUrl);
			BufferedReader in           = new BufferedReader(
				new InputStreamReader(storageFile));
		String s="";
		while(true){
			String st= in.readLine();
			if(st==null){
				break;
			}
			st+="\n";
			s+=st;
		}
	}
	
	
	public void write(String fileUrl) throws IOException{
		this.fileUrl=fileUrl;

		
		FileOutputStream saleFile = new FileOutputStream(
				SALE_FILE_NAME);
		BufferedWriter  out  	 = new BufferedWriter(
				new OutputStreamWriter(saleFile));
		out.flush();
		out.newLine();
		out.append(s);
		out.close();
	}
	
	public void write() throws Exception{
		//InputStream storageFile = getClass().getResourceAsStream(fileUrl);

		FileInputStream storageFile = new FileInputStream(fileUrl);
			BufferedReader in           = new BufferedReader(
				new InputStreamReader(storageFile));
		String s="";
		while(true){
			String st= in.readLine();
			if(st==null){
				break;
			}
			st+="\n";
			s+=st;
		}
		
		FileOutputStream saleFile = new FileOutputStream(
				SALE_FILE_NAME);
		BufferedWriter  out  	 = new BufferedWriter(
				new OutputStreamWriter(saleFile));
		out.flush();
		out.newLine();
		out.append(s);
		out.close();
	}
	
	/**
	 * Run the class and check it
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub

		FileInputStream storageFile = new FileInputStream(fileUrl);
			BufferedReader in           = new BufferedReader(
				new InputStreamReader(storageFile));
		while(true){
			String s = in.readLine();
			if(s==null){
				break;
			}
			System.out.println(s);
		}
	}
	
	public void setPath(String url){
		SALE_FILE_NAME=url;
	}

}
